<%
    Users user = Trader.getUser(request.getParameter("uid"));
	wstrader.task.traffic.si.Instruction task = user.traffic.si.sIns;

	if (!user.Authenticated()) {
		response.sendRedirect("logon.jsp");
		return;
	}
	((Tasks)task.getOwner()).clearFocus();
	task.setFocus(true);	
	Trader.window_width = "90%";

%>

<%@include file="../header.jsp"%>
<link href="style.css" rel="stylesheet" type="text/css">

<script language="javascript">
function doFilter()
{
	var form = document.formMain;
	form.action = "traffic.si.jsp";
	form.submit();
}

function clickCardView()
{
	var form = document.formMain;
	form.action = "traffic.si.card-view.jsp";
	form.submit();	
}

function cardViewClick(row)
{
	var form = document.formMain;
	form.shipping_instruction.value = row.id;
	dblClick(row);
}

function new_SI()
{
	var form = document.formMain;
	
	var e = document.getElementById("contract_id");
	var strUser = e.options[e.selectedIndex].value;
	
	if (strUser != "0")
	{
		form.new_rec.value="1";
		form.action = "traffic.si.card-view.jsp";
		form.submit();
	}
	else
	{
		alert("Please select a sales contract to select a new SI");
	}

}
	
</script>
<form method="POST" name="formMain" action="" onSubmit="">		
<table width="100%"  border="0" cellspacing="0" cellpadding="0">
<tr>
	<td><img src="images/shipping-instruction.jpg" width="300" height="30"></td>
</tr>
<tr>
	<td><table width="100%"  border="0" cellpadding="0" cellspacing="1" class="style2">
          <tr bgcolor="#EEEEEE" class="style3" align="center" style="font-weight:bold">
            <td width="12%">Contract Ref </td>
            <td width="13%">Broker No</td>
            <td width="14%">Buyer</td>
            <td width="18%">Origin</td>
            <td width="12%">Quality</td>
            <td width="20%">Grade&nbsp;<input type="text" name="grade_code" id="grade_code" class="style11" style="height:16px; width:40px; text-align:center" onChange="codeChanged(this);doPost();" onKeyUp="keyUp(this);"></td>
            <td width="11%">Last Date</td>
          </tr>
<tr>
            <td valign="top"><select name="contract_id" id="contract_id" size="7" class="style11" style="width:100%;" onChange="setValue('contract_no',0);doPost()">
              <option value="0" selected>All</option>
              <%task.getResponse().setOption(task.getContract_List());%>
              <%task.getResponse().setSelected("contract_id");%>
            </select></td>
            <td valign="top"><select name="contract_no" id="contract_no" size="7" class="style11" style="width:100%;" onChange="setValue('supplier_id',0);doPost()">
              <option value="0" selected>All</option>
              <%task.getResponse().setOption(task.getBroker_List());%>
              <%task.getResponse().setSelected("contract_no");%>
            </select></td>		  
             <td valign="top"><select name="supplier_buyer_id" id="supplier_buyer_id" size=7 class="style11" style="width:100%;" onChange="doPost();">
               <option value="0" selected>All</option>
               <%task.getResponse().setOption(task.getCompanyList("supplier,buyer"));%>
               <%task.getResponse().setSelected("supplier_buyer_id");%>
             </select></td>
             <td valign="top"><select name="origin_id" id="origin_id" size=7 class="style11" style="width:100%;" onChange="setValue('quality_id',0);setValue('grade_id',0);doPost();">
               <option value="0" selected>All</option>
               <%task.getResponse().setOption(task.getMasterList("origin_master"));%>
               <%task.getResponse().setSelected("origin_id");%>
             </select></td>
             <td valign="top"><select name="quality_id" id="quality_id" size=7 class="style11" style="width:100%;" onChange="setValue('grade_id',0);doPost();">
               <option value="0" selected>All</option>
               <%task.getResponse().setOption(task.getMasterList("quality_master"));%>
               <%task.getResponse().setSelected("quality_id");%>
             </select></td>
             <td valign="top"><select name="grade_id" id="grade_id" size=7 class="style11" style="width:100%;" onChange="doPost();">
               <option value="0" selected>All</option>
               <%task.getResponse().setOption(task.getMasterList("grade_master"));%>
               <%task.getResponse().setSelected("grade_id");%>
             </select></td>
             <td valign="top">
               <select name="filter_date_from" id="filter_date_from" size=7 class="style11" style="width: 100%;" onChange="doPost()">
                 <option value="<%=Utils.nullDate%>" selected>All</option>
                 <%//task.getResponse().setOption(task.getSI_Date_List());%>
                 <%//task.getResponse().setSelected("filter_date_from","" + task.getRequest().getValueDate("filter_date_from"));%>
               </select>
</td>
      </tr>    </table></td>
</tr>
	<tr id="si_list_view">
		<td><table width="100%"  border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><table width="100%"  border="0" cellpadding="0" cellspacing="1" class="style2">
              <script language="javascript">
	var table = 'traffic.si';
            </script>
              <tr align="center" bgcolor="#EEEEEE" style="font-weight:bold; cursor:pointer" title='Click on columns to sort' onMouseOver="window.status='Click on columns to sort'">
                <td width="30" rowspan="2" onClick="doPost();"><img src="images/refresh.gif" width="18" height="18" class="style3"></td>
                <td width="110" rowspan="2" onClick="doSort(table,'ref_number')" id="h_detail_1">SI Ref</td>
                <td width="120"  rowspan="2" onClick="doSort(table,'supplier')">Buyer</td>
                <td width="80"  rowspan="2" onClick="doSort(table,'origin')">Origin</td>
                <td width="80"  rowspan="2" onClick="doSort(table,'quality')">Quality</td>
                <td width="30"  rowspan="2" onClick="doSort(table,'grade_code')">Code</td>
                <td rowspan="2" onClick="doSort(table,'grade')">Grade</td>
                <td width="80" rowspan="2">Packing</td>
                <td colspan="3">Tons</td>
                <td colspan="2">Del. Period</td>
                <td width="15">&nbsp;</td>
              </tr>
              <tr align="center" bgcolor="#EEEEEE" style="font-weight:bold; cursor:pointer">
                <td width="60">Total</td>
                <td width="60">Del.</td>
                <td width="60">Pend.</td>
                <td width="70" onClick="doSort(table,'from_date')">From</td>
                <td width="70" onClick="doSort(table,'to_date')">To</td>
                <td>&nbsp;</td>
              </tr>
            </table></td>
          </tr>
          <tr>
            <td><div style="overflow:scroll; height:250px;">		  
			  <table width="100%"  border="0" cellpadding="0" cellspacing="1" class="style2">
<script language="javascript">
	var table = 'traffic.si';
</script>			  
<%
	Record rc = new Record(task.getSI_ListView());
	rc.beforeFirst();
	float total_tons = 0;
	float total_delivered_tons = 0;	
	while (rc.next()) {
		String color = task.getColor(rc.getIntValue("status"));
		float pending_tons = rc.getFloatValue("tons") - (rc.getFloatValue("shipton")/1000);
		total_tons += rc.getFloatValue("tons");
		total_delivered_tons += (rc.getFloatValue("shipton")/1000);
%>				
                <tr style="font-size:11px" onClick="highlightOn(this);" onDblClick="cardViewClick(this);" id=<%=rc.getInt("id")%>>
                  <td width="30" align="right"><%=rc.getRow()%></td>
                  <td width="110" style="color:<%=color%>"><%=rc.getStringValue("ref_number")%></td>
                  <td width="80" style="display:none"><%//=rc.getStringValue("contract_ref_number")%></td>
                  <td width="120"><%=task.getFieldValueForId("company_master","name",rc.getIntValue("buyer_id"))%></td>
                  <td width="80"><%=task.getFieldValueForId("origin_master","name",rc.getIntValue("origin_id"))%></td>
                  <td width="80"><%=task.getFieldValueForId("quality_master","name",rc.getIntValue("quality_id"))%></td>
                  <td width="30"><%=rc.getString("grade_code")%></td>
                  <td><%=rc.getString("name")%></td>
                  <td width="80"><%=task.getFieldValueForId("packing_master","name",rc.getIntValue("packing_id"))%></td>
                  <td width="60" align="right"><%=rc.getFloat("tons")%></td>
                  <td width="60" align="right"><%=rc.getFloat("shipton")%></td>
                  <td width="60" align="right"><%=Utils.numberToStr(pending_tons)%></td>
                  <td width="70" align="center"><%=rc.getDate("from_date")%></td>
                  <td width="70" align="center"><%=rc.getDate("to_date")%></td>
                </tr>
<%
	}
	rc.close();
%>				
              </table>
</div></td>
          </tr>
          <tr>
            <td><table width="100%"  border="0" class="style11">
              <tr bgcolor="#EEEEEE" style="font-weight:bold;"  align="right">
                <td width="650" align="center">Total</td>
                <td width="55"><%=Utils.numberToStr(total_tons)%></td>
                <td width="55"><%=Utils.numberToStr(total_delivered_tons)%></td>
                <td width="55"><%=Utils.numberToStr(total_tons-total_delivered_tons)%></td>
                <td>&nbsp;</td>
              </tr>
            </table></td>
          </tr>
        </table></td>
	</tr>
	<tr id="si_report" style="display:none">
		<td><table border="1" cellpadding="0" cellspacing="0" hspace="0" vspace="0" width="100%">
          <tr valign="top">
            <td height="250px">
              <table width="100%"  border="0" class="style2">
                <tr class="style1">
                  <td height="42">&nbsp;</td>
                  <td height="42" colspan="3">Submit more information for creating report </td>
                  <td width="9%">&nbsp;</td>
                </tr>
                <tr>
                  <td width="6%">&nbsp;</td>
                  <td width="9%">From date </td>
                  <td width="8%"><input type="text" name="report_date_from" id="report_date_from" style="width:80px"></td>
                  <td width="62%"><img src="../shared/images/calendar.gif" width="20" height="20" onclick="popUpCalendar(this,'report_date_from','dd-mmm-yy');"></td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td>&nbsp;</td>
                  <td>To Date </td>
                  <td><input type="text" name="report_date_to" id="report_date_to" style="width:80px"></td>
                  <td><img src="../shared/images/calendar.gif" width="20" height="20" onclick="popUpCalendar(this,'report_date_to','dd-mmm-yy');"></td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td> <img src="images/update.gif" width="15" height="15" onClick="doTask(4);"> <img src="images/delete.gif" width="15" height="15" onClick="cancelReport('si');"> </td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                </tr>
            </table></td>
          </tr>
        </table></td>
	</tr>

<tr>
	<td>  <tr>
  	  <td><table width="100%"  border="0" class="style2">
        <tr id="si_buttons" style="display:">
          <td width="12%"><img src="images/new.gif" border="0" width="15" height="15" onClick="new_SI();"></td>
          <td width="88%" colspan="6" align="right"> 
		  	<img src="images/report.jpg" width="55" height="18" onClick="doReport('si');"> 
		  	<img id="bt_card_view" src="images/cardview.jpg" width="55" height="18" onClick="clickCardView();"> 
		</td>
        </tr>
      </table></td>
	</tr>
</td>
</tr>

</table>
	<input type="hidden" name="uid"  id="uid"  value="<%=user.getuid()%>">
	<input type="hidden" name="task_id"  id="task_id"  value="0">
	<input type="hidden" name="sorted_field"  id="sorted_field"  value="">
	<input type="hidden" name="sorted_table"  id="sorted_table"  value="">
	<input type="hidden" name="view" id="view" value="<%=task.getRequest().getIntValue("view")%>">	
	<input type="hidden" name="inst_id"  id="inst_id"  value="0">
    <input name="new_rec" type="hidden" id="new_rec" value="0">
    <input name="shipping_instruction" type="hidden" id="shipping_instruction" value="0">
</form>
<script language="javascript">
	setFocus('grade_code');
</script>		
<%@include file="../footer.jsp"%>